//
//  SHMainViewController.swift
//  SHWeibo
//
//  Created by jingming wang on 16/7/19.
//  Copyright © 2016年 cpy.name. All rights reserved.
//

import UIKit

class SHMainViewController: UITabBarController {
    
    override func loadView() {
        super.loadView()
        
        let tabBar = SHTabBar()
        // 只读属性
        //self.tabBar = tabBar
        // 通过kvc 设置
        setValue(tabBar, forKey: "tabBar")
        
        // 按钮监听回调
        tabBar.closure = {[weak self] in
            // 创建view
            let composeView = SHComposeView()
            composeView.showComposeView(self!)
        
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        addChildViewController(
            SHHomeViewController(),
            title: "首页",
            imgName: "tabbar_home"
        )
        addChildViewController(
            SHMessageViewController(),
            title: "消息",
            imgName: "tabbar_message_center"
        )
        addChildViewController(
            SHDiscoveryViewController(),
            title: "发现",
            imgName: "tabbar_discover"
        )
        addChildViewController(
            SHProfileViewController(),
            title: "我",
            imgName: "tabbar_profile"
        )
        
        
    }

    //MARK: - 添加子控制器
    func addChildViewController(vc:UIViewController, title: String, imgName: String) {
        
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imgName)
        
        addChildViewController(UINavigationController(rootViewController:vc))
        
    }

}
